package com.book.book.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.book.book.domain.WantSeeDO;
import com.book.book.service.WantSeeService;
import com.book.common.utils.PageUtils;
import com.book.common.utils.Query;
import com.book.common.utils.R;

/**
 * 用户心愿表
 * 
 * @author siyuan
 * @email 894266364@qq.com
 * @date 2018-01-30 16:51:09
 */
 
@Controller
@RequestMapping("/book/wantSee")
public class WantSeeController {
	@Autowired
	private WantSeeService wantSeeService;
	
	@GetMapping()
	@RequiresPermissions("book:wantSee:wantSee")
	String WantSee(){

		return "book/wantSee/wantSee";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("book:wantSee:wantSee")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<WantSeeDO> wantSeeList = wantSeeService.listWithUserInfo(query);
		int total = wantSeeService.count(query);
		PageUtils pageUtils = new PageUtils(wantSeeList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("book:wantSee:add")
	String add(){
	    return "book/wantSee/add";
	}

	@GetMapping("/edit/{id}")
//	@RequiresPermissions("book:wantSee:edit")
	String edit(@PathVariable("id") Integer id,Model model){
		WantSeeDO wantSee = wantSeeService.get(id);
		model.addAttribute("wantSee", wantSee);
	    return "book/wantSee/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
//	@RequiresPermissions("book:wantSee:add")
	public R save( WantSeeDO wantSee){
		if(wantSeeService.save(wantSee)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
//	@RequiresPermissions("book:wantSee:edit")
	public R update( WantSeeDO wantSee){
		wantSeeService.update(wantSee);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("book:wantSee:remove")
	public R remove( Integer id){
		if(wantSeeService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("book:wantSee:batchRemove")
	public R remove(@RequestParam("ids[]") Integer[] ids){
		wantSeeService.batchRemove(ids);
		return R.ok();
	}
	
}
